<template>
  <div>
    <van-sticky>
      <van-nav-bar
          title="试题列表"
          left-arrow
          @click-left="onClickLeft"
      />
    </van-sticky>
    <div v-for="ele in data">
      <ul class="news-detail-item" :key="ele._id">
        <li class="left">
          <h2>试卷名称：{{ ele.title }}</h2>
          <p>分类：{{ ele.questionType }}</p>
          <p>单选题：{{ ele.singleCount }}</p>
          <p>多选题：{{ ele.multipleCount }}</p>
          <p>判断题：{{ ele.judgementCount }}</p>
          <p>简答题：{{ ele.answerCount }}</p>
          <p><i class="fa fa-calendar" aria-hidden="true"></i> {{ formatTime(ele.createTime) }}</p>
        </li>
        <li class="right">
          <van-button type="primary" @click="exam(ele)">开始作答</van-button>&nbsp;&nbsp;
        </li>
      </ul>
    </div>
    <van-empty description="暂无相关试题！！！" v-if="data.length == 0"/>
  </div>
</template>

<script setup lang="ts">
import {ref,reactive,toRefs} from "vue";
import {useRoute,useRouter} from "vue-router";
import {getPageList} from '../api/page'
import {formatTime} from "../utils/date";
import {Notify} from "vant";
const router = useRouter()
const route = useRoute()
const state = reactive({
  data:[],
  type:'' as any,
  uid:'' as any
})
let {data,type,uid}=toRefs(state)
type.value = route.query.type
uid.value = localStorage.getItem('id')

const onClickLeft = ()=>{
  router.back()
}
const getPages = async (type) =>{
  let response = await getPageList(type)
  console.log(response)
  data.value = response.data.questionList
}
const exam =(ele) =>{
  if (uid.value ==""){
    console.log('uid：',uid.value)
    Notify({type:'danger',message:'请先登录后再操作',duration:800})
  }else{
    console.log("ele:",ele)
    router.push('/page/'+ele._id)
  }

}
getPages(type.value)
</script>

<style scoped lang="less">
.news-detail-item {
  display: flex;
  border-bottom: 1px solid #e4e4e4;
  padding: 0.3rem 0.1rem;
  justify-content: space-between;
  .left {
    padding-left: 0.2rem;
    margin-right: 0.4rem;
    width: 60%;
    > h2 {
      -webkit-box-sizing: border-box;
      font-size: .42rem;
      line-height: 1.2;
      color: #1a1a1a;
      font-weight: normal;
      text-overflow: -o-ellipsis-lastline;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 10;
      -webkit-box-orient: vertical;
    }
    > p {
      padding: 0.1rem 0;
      font-size: 0.24rem;
      color: #949494;
    }
  }
  .right {
    width: 40%;
    display: flex;
    justify-content: center;
  }
}
</style>
